// pages/start/start.jsv
var app = getApp(), api = require("../../api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num:3,
    LoadTime:'',
    animation:{},
    logo:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (option) {
    var that = this;
    if (option && option.q) {
      var devId = that.getRequest(option.q)
      app.globalData.equipment_id = devId;
    }
   app.globalData.ad =true;
   app.request({
     url:api.setting,
     success:function(res){
      that.setData({
        logo: res.data.start_img
      })
       that.reciprocal()
     }
   })
  
  },

  reciprocal:function(){
    let that = this
    let num = this.data.num;
    that.setData({
      LodaTime: setInterval(() => {
        num--
        that.setData({
          num
        })
        if (num <= 0) {
          clearInterval(that.data.LodaTime)
          wx.switchTab({
            url: '../home/home'
          })
         
        }
      }, 1000)
    })
  },
  getRequest: function (url) {
    if (!url)
      return
    let id;
    if (url.indexOf("") != -1) {
      id = url.split('%3F')[1].split('%3D')[1];
    }
    return id;
  },
  goHome: function(){
    clearInterval(this.data.LodaTime)
    wx.switchTab({
      url: '../home/home'
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var animation = wx.createAnimation({
      duration: 2000,
      timingFunction: 'ease',
      delay:800
    })
    this.animation = animation
    animation.opacity(1).step()
    this.setData({
      animation: animation.export()
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearInterval(this.data.LoadTime)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})